import logging
import time


from selenium.webdriver.chrome import webdriver
from selenium.webdriver.common.by import By

from yizuauto.common.dologs import DoLog

dolog = DoLog().set_get_logger(logging.INFO)

# wd = webdriver.WebDriver()
# wd.get("http://192.168.88.100/user.php")


class RegPage:
    province = (By.NAME, "province")
    pro = (By.XPATH, "//*[@id='selProvinces_0']/option[2]")
    city = (By.CSS_SELECTOR, "select[name='city']")
    city1 = (By.XPATH, '//*[@id="selCities_0"]/option[2]')
    dt = (By.CSS_SELECTOR, "select[name='district']")
    dt2 = (By.XPATH, '//*[@id="selDistricts_0"]/option[2]')
    uname = (By.CSS_SELECTOR, "input[name='consignee']")
    address = (By.CSS_SELECTOR, "input[name='address']")
    tel = (By.CSS_SELECTOR, "input[name='tel']")
    # qr = (By.CSS_SELECTOR, "input[name='submit']")

    def dizhi(self,wd, a, b, c):
        # wd = webdriver.WebDriver()
        wd.get("http://192.168.88.100/user.php")
        wd.implicitly_wait(10)

        wd.find_element(By.CSS_SELECTOR, 'input[name="username"]').send_keys('张丽丽')
        wd.find_element(By.CSS_SELECTOR, 'input[name="password"]').send_keys('1234561')
        wd.find_element(By.CSS_SELECTOR, 'input[name="submit"]').click()
        time.sleep(3)

        wd.find_element_by_link_text('收货地址').click()
        time.sleep(2)

        wd.find_element(*self.province).click()
        wd.find_element(*self.pro).click()
        time.sleep(3)
        wd.find_element(*self.city).click()
        wd.find_element(*self.city1).click()
        time.sleep(3)
        wd.find_element(*self.dt).click()
        wd.find_element(*self.dt2).click()
        time.sleep(3)

        try:
            wd.find_element(*self.uname).send_keys(a)
            wd.find_element(*self.address).send_keys(b)
            wd.find_element(*self.tel).send_keys(c)
            time.sleep(3)
        except Exception as e:
            dolog.error("地址失败！！！")
        else:
            dolog.info("地址成功！！！")
        finally:
            dolog.info("结束了！！！")

        # wd.find_element(*self.qr).click()


if __name__ == '__main__':
    wd = webdriver.WebDriver()
    a = RegPage()
    a.dizhi(wd, '张丽丽', '北京', '1423454565')
    time.sleep(3)
